﻿<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<hta:application
	id="hta"
	applicationName="灌水机器人"
	border="thick"
	borderStyle="normal"
	caption="yes"
	contextMenu="yes"
	innerBorder="no"
	maximizeButton="yes"
	minimizeButton="yes"
	navigable="yes"
	icon="notepad.exe"
	scroll="no"
	scrollflat="no"
	selection="no"
	showIntaskbar="yes"
	singleInstance="no"
	sysmenu="yes"
	version="0.3"
	windowState="normal"
/>
<style type="text/css">
body{margin:0;font-family:"宋体";font-size:12px;}
#textarea_log{width:100%;height:50%;}
#textarea_url{width:100%;height:50%;}
table{width:100%;height:100%;}
#td_tools{height:25px;}
#userData{behavior:url(#default#userdata);}
</style>
<script src="Common.js"></script>
<script src="Local.js"></script>
</head>
<body leftmargin="0" topmargin="0" rightmargin="0" buttommargin="0">
<input id="userdata" type="hidden"/>
<table colspan="0" rowspan="0">
	<tr><td id="td_tools">
		<input id="button_download" type="button" value="开始下载"/>
		<input id="button_stop" type="button" value="停止"/>
		下载目录：<input id="text_downloadPath" title="下载目录" value="D:\download"/>
		<input id="button_downloadPath" type="button" value="选择目录"/>&nbsp;
	</td></tr>
	<tr><td>
		<textarea id="textarea_url"></textarea>
		<textarea id="textarea_log"></textarea>
	</td><tr>
</table>
<script>
Common.setEvent(window, "load", function() {
	document.title = "批量下载 - 2011清洁工版";
	var userdata = Common.$("userdata");
	userdata.load("downloadSetting");
	Common.$("text_downloadPath").value = userdata.getAttribute("downloadPath") || Common.$("text_downloadPath").value; 
	Common.$("textarea_url").value = userdata.getAttribute("urls") || Common.$("textarea_url").value; 
	Common.$("button_downloadPath").onclick = function() {
		var folder = Local.folderDialog(Common.$("text_downloadPath").title);
		if (!folder) return;
		Common.$("text_downloadPath").value = folder;
	};

	Common.$("button_download").onclick = function() {
		var urls = Common.$("textarea_url").value.split(/\r?\n/);
		var path = Common.$("text_downloadPath").value;
		userdata.setAttribute("downloadPath", Common.$("text_downloadPath").value); 
		userdata.setAttribute("urls", Common.$("textarea_url").value);
		userdata.save("downloadSetting");

		for (var i = 0; i < urls.length; i++) {
			var url = urls[i];
			Local.download(url, path + "//" + url.replace(/^.*?(?=[^\/]*$)/, ""));
			Common.$("textarea_log").value += [url, "\n"].join("");
		}
	};
});
</script>
</body>
</html>